package me.spring.cloud.common.components.rabbitmq.service;

import me.spring.cloud.common.components.rabbitmq.message.IMessage;
import me.spring.cloud.common.components.rabbitmq.message.RetryMessage;
import me.spring.cloud.common.components.rabbitmq.util.RabbitMqUtil;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author luffy
 * @description: 消息发送
 * @date 2019-05-25 13:23
 */
public class RqMessageService implements IMessageService {

  @Autowired
  private AmqpTemplate amqpTemplate;

  /**
   * @Author luffy
   * @Description 发送字符串消息
   * @Date 2019-05-30 08:55
   * @Param [queueName, message]
   * @Return void
   **/
  @Override
  public void send(String queueName, String message) {
    RabbitMqUtil.sendMessage(amqpTemplate, queueName, message);
  }

  /**
   * @Author luffy
   * @Description 发送自定义消息
   * @Date 2019-05-30 08:55
   * @Param [queueName, message]
   * @Return void
   **/
  @Override
  public void send(String queueName, IMessage message) {
    RabbitMqUtil.sendMessage(amqpTemplate, queueName, message);
  }

  /**
   * @Author luffy
   * @Description 发送延迟消息
   * @Date 2019-05-30 08:55
   * @Param [queueName, exchangeName, iMessage, second]
   * @Return void
   **/
  @Override
  public void send(String queueName, String exchangeName, IMessage iMessage, long second) {
    RabbitMqUtil.sendDelayMessage(amqpTemplate, exchangeName, queueName, iMessage, second);
  }

  /**
   * @Author luffy
   * @Description 发送延迟重试消息
   * @Date 2019-05-30 08:55
   * @Param [queueName, exchangeName, message, second]
   * @Return void
   **/
  @Override
  public void send(String queueName, String exchangeName, RetryMessage retryMessage, long second) {
    RabbitMqUtil.sendDelayMessage(amqpTemplate, exchangeName, queueName, retryMessage, second);
  }
}
